package com.teach.food.service.Impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.teach.commons.Id;
import com.teach.dto.FoodGoodsDTO;
import com.teach.food.entity.FoodGoods;
import com.teach.food.service.FoodGoodsService;
import com.teach.mapper.FoodGoodsMapper;
@Service
public class FoodGoodsServiceImpl implements FoodGoodsService {
	@Autowired
	private FoodGoodsMapper mapper;
	@Autowired
	private Id id;
	
	@Override
	public void add(FoodGoods foodGoods) {
		foodGoods.setFoodGoodsId((int) id.nextId());
		mapper.insert(foodGoods);
	}

	@Override
	public void modify(FoodGoods foodGoods) {
		mapper.updateByPrimaryKeySelective(foodGoods);
		
	}

	@Override
	public void delete(Integer foodGoodsId) {
		mapper.deleteByPrimaryKey(foodGoodsId);
		
	}

	@Override
	public FoodGoods get(Integer foodGoodsId) {
		return mapper.selectByPrimaryKey(foodGoodsId);
	}

	@Override
	public List<FoodGoods> list2(FoodGoodsDTO search) {
		PageInfo<FoodGoods> page = PageHelper.startPage(search.getCurrent(), search.getRowMax(),false).doSelectPageInfo(()->{
			mapper.select(search);
		});
		return page.getList();
	}

	@Override
	public PageInfo<FoodGoods> page(FoodGoodsDTO search) {
		PageInfo<FoodGoods> page = PageHelper.startPage(search.getCurrent(), search.getRowMax()).doSelectPageInfo(()->{
			mapper.select(search);
		});
		return page;
	}

	@Override
	public List<FoodGoods> list() {
//		return mapper.list();
		return null;
	}

}
